package extraWork;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.LineBorder;

@SuppressWarnings("serial")
public class AboutFrame extends JFrame implements ActionListener, CommonConstants {
	int xLoc = 0;
	int yLoc = 0;

	public AboutFrame(String title, String msg, int width, int height, int xWinLoc, int yWinLoc, int winHeight, int winWidth) {
		super(title);
		JTextArea msgArea = new JTextArea(msg);
		msgArea.setEditable(false);
		JButton close = new JButton("Close");
		close.setActionCommand(CLOSE_ABOUT);
		close.addActionListener(this);
		JPanel innerPanel = new JPanel();
		innerPanel.setBackground(Color.WHITE);
		innerPanel.add(close);
		JPanel panel = new JPanel(new GridLayout(3, 1));
		panel.setBorder(new LineBorder(Color.BLACK, 2, true));
		panel.setBackground(Color.WHITE);
		panel.add(msgArea);
		panel.add(innerPanel);
		this.setSize(width, height);
		this.getContentPane().add(panel);
		this.xLoc = xWinLoc + ((winWidth - this.getWidth()) / 2);
		this.yLoc = yWinLoc + ((winHeight - this.getHeight()) / 2);
	}

	public void run() {
		this.setBackground(Color.WHITE);
		this.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
		this.setUndecorated(true);
		this.pack();
		this.setLocation(xLoc, yLoc);
		this.setVisible(true);
	}

	public void actionPerformed(ActionEvent pE) {
		if (pE.getActionCommand().equals(CLOSE_ABOUT)) {
			this.dispose();
		}
	}

	public void paint(Graphics g) {
		super.paint(g);
		try {
			Image img = ImageIO.read(this.getClass().getResource("img/icon.JPG"));
			g.drawImage(img, 145, 90, null);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
